<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="​     关于C语言中的0长度数组，被使用起来的话还是很妙的，下面的内容部分来自于互联网，参考了以下几篇博文： ​     https:&#x2F;&#x2F;blog.csdn.net&#x2F;zhaixuebuluo&#x2F;article&#x2F;details&#x2F;86657929 ， ​     https:&#x2F;&#x2F;kernel.blog.csdn.net&#x2F;article&#x2F;details&#x2F;64131322?utm_medium&#x3D;dist">
<meta property="og:type" content="article">
<meta property="og:title" content="C语言0长度数组">
<meta property="og:url" content="http://example.com/2021/06/11/C%E8%AF%AD%E8%A8%800%E9%95%BF%E5%BA%A6%E6%95%B0%E7%BB%84/index.html">
<meta property="og:site_name" content="学无止境">
<meta property="og:description" content="​     关于C语言中的0长度数组，被使用起来的话还是很妙的，下面的内容部分来自于互联网，参考了以下几篇博文： ​     https:&#x2F;&#x2F;blog.csdn.net&#x2F;zhaixuebuluo&#x2F;article&#x2F;details&#x2F;86657929 ， ​     https:&#x2F;&#x2F;kernel.blog.csdn.net&#x2F;article&#x2F;details&#x2F;64131322?utm_medium&#x3D;dist">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-06-11T07:24:49.000Z">
<meta property="article:modified_time" content="2021-06-11T07:24:49.000Z">
<meta property="article:author" content="xudonglei">
<meta property="article:tag" content="C语言">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/2021/06/11/C%E8%AF%AD%E8%A8%800%E9%95%BF%E5%BA%A6%E6%95%B0%E7%BB%84/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>C语言0长度数组 | 学无止境</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">学无止境</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Do not bb, show me the example</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/06/11/C%E8%AF%AD%E8%A8%800%E9%95%BF%E5%BA%A6%E6%95%B0%E7%BB%84/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          C语言0长度数组
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-06-11 15:24:49" itemprop="dateCreated datePublished" datetime="2021-06-11T15:24:49+08:00">2021-06-11</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/06/11/C%E8%AF%AD%E8%A8%800%E9%95%BF%E5%BA%A6%E6%95%B0%E7%BB%84/" class="post-meta-item leancloud_visitors" data-flag-title="C语言0长度数组" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/06/11/C%E8%AF%AD%E8%A8%800%E9%95%BF%E5%BA%A6%E6%95%B0%E7%BB%84/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/06/11/C%E8%AF%AD%E8%A8%800%E9%95%BF%E5%BA%A6%E6%95%B0%E7%BB%84/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>​     关于C语言中的0长度数组，被使用起来的话还是很妙的，下面的内容部分来自于互联网，参考了以下几篇博文：</p>
<p>​     <a target="_blank" rel="noopener" href="https://blog.csdn.net/zhaixuebuluo/article/details/86657929">https://blog.csdn.net/zhaixuebuluo/article/details/86657929</a> ，</p>
<p>​     <a target="_blank" rel="noopener" href="https://kernel.blog.csdn.net/article/details/64131322?utm_medium=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-1.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-1.control">https://kernel.blog.csdn.net/article/details/64131322?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control</a> 。</p>
<h3 id="1-什么是零长度数组"><a href="#1-什么是零长度数组" class="headerlink" title="1. 什么是零长度数组"></a>1. 什么是零长度数组</h3><p>​    零长度数组就是长度为0的数组(也叫柔性数组)，它不占用内存存储空间。零长度数组一般单独使用的机会很少，它常常作为结构体的一个成员，构成一个变长结构体。并且在结构体中，数组为0的数组必须在最后声明。</p>
<h3 id="2-零长度数组用途"><a href="#2-零长度数组用途" class="headerlink" title="2. 零长度数组用途"></a>2. 零长度数组用途</h3><p>​    我们以实际的例子来分析一下，为什么要使用零长度数组。考虑下面这个场景：比如说准备发送一个数据缓冲区里面的数据, 缓冲区包括一个len字段和data字段, 分别标识数据的长度和传输的数据。</p>
<h4 id="2-1-定长包"><a href="#2-1-定长包" class="headerlink" title="2.1 定长包"></a>2.1 定长包</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//  定长缓冲区</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">max_buffer</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    <span class="keyword">int</span>     len;</span><br><span class="line">    <span class="keyword">char</span>    data[MAX_LENGTH];</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<p>​    <strong>数据结构的大小：</strong></p>
<p>​    考虑对齐, 那么数据结构的大小 &gt;= sizeof(int) + sizeof(char) * MAX_LENGTH</p>
<p>​    由于考虑到数据的溢出, data 数组长度一般会设置得足够长足以容纳最大的数据, 因此 max_buffer 中的data数组很多情况下都没有填满数据, 因此造成了浪费。</p>
<p>​    <strong>数据包构造：</strong></p>
<p>​    假如要发送 CURR_LENGTH = 1024个字节：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> ((mbuffer = (struct max_buffer *)<span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(struct max_buffer))) != <span class="literal">NULL</span>)</span><br><span class="line">&#123;</span><br><span class="line">    mbuffer-&gt;len = CURR_LENGTH;</span><br><span class="line">    <span class="built_in">memcpy</span>(mbuffer-&gt;data, <span class="string">&quot;Hello World&quot;</span>, CURR_LENGTH);</span><br><span class="line"></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;%d, %s\n&quot;</span>, mbuffer-&gt;len, mbuffer-&gt;data);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>​    前部分 4 个字节 p-&gt;len, 作为包头，这个包头是用来描述紧接着包头后面的数据部分的长度，这里是 1024, 所以前四个字节赋值为 1024。而紧接其后的内存是真正的数据部分, 通过 p-&gt;data, 最后, 进行一个 memcpy()内存拷贝, 把要发送的数据填入到这段内存当中。</p>
<h4 id="2-2-指针数据包"><a href="#2-2-指针数据包" class="headerlink" title="2.2  指针数据包"></a>2.2  指针数据包</h4><p>​    如果将上面的长度为 MAX_LENGTH的定长数组换为指针, 每次使用时动态的开辟 CURR_LENGTH 大小的空间, 那么就避免造成 MAX_LENGTH - CURR_LENGTH空间的浪费, <strong>只浪费了一个指针域的空间</strong>。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">point_buffer</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    <span class="keyword">int</span>     len;</span><br><span class="line">    <span class="keyword">char</span>    *data;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<p>​    <strong>数据结构的大小：</strong></p>
<p>​    考虑对齐, 那么数据结构的大小 &gt;= sizeof(int) + sizeof(char *)</p>
<p>​    <strong>数据包构造：</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> ((pbuffer = (struct point_buffer *)<span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(struct point_buffer))) != <span class="literal">NULL</span>)</span><br><span class="line">&#123;</span><br><span class="line">       pbuffer-&gt;len = CURR_LENGTH;</span><br><span class="line">       <span class="keyword">if</span> ((pbuffer-&gt;data = (<span class="keyword">char</span> *)<span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(<span class="keyword">char</span>) * CURR_LENGTH)) != <span class="literal">NULL</span>)</span><br><span class="line">       &#123;</span><br><span class="line">           <span class="built_in">memcpy</span>(pbuffer-&gt;data, <span class="string">&quot;Hello World&quot;</span>, CURR_LENGTH);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">           <span class="built_in">printf</span>(<span class="string">&quot;%d, %s\n&quot;</span>, pbuffer-&gt;len, pbuffer-&gt;data);</span><br><span class="line">       &#125;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>
<ol>
<li><p>首先, 需为结构体分配一块内存空间;</p>
</li>
<li><p>其次再为结构体中的成员变量分配内存空间.</p>
<p><strong>这样两次分配的内存是不连续的, 需要分别对其进行管理</strong>. </p>
</li>
</ol>
<p>开辟空间时, 需要额外开辟数据域的空间, 释放时候也需要显示释放数据域的空间, 但是实际使用过程中, 往往在函数中开辟空间, 然后返回给使用者指向 struct point_buffer 的指针, 这时候我们并不能假定使用者了解我们开辟的细节, 并按照约定的操作释放空间, 因此使用起来多有不便, 甚至造成内存泄漏。</p>
<h4 id="2-3-变长数据缓冲区"><a href="#2-3-变长数据缓冲区" class="headerlink" title="2.3 变长数据缓冲区"></a><strong>2.3 变长数据缓冲区</strong></h4><p>​    定长数组使用方便, 但是却浪费空间, 指针形式只多使用了一个指针的空间, 不会造成大量空间分浪费, 但是使用起来需要多次分配, 多次释放。<strong>那有没有一种方法，即能够既不浪费空间, 又使用方便的呢?这就引出了0长度数组</strong>。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//  0长度数组</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">zero_buffer</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    <span class="keyword">int</span>     len;</span><br><span class="line">    <span class="keyword">char</span>    data[<span class="number">0</span>];</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<p>​    <strong>数据结构的大小：</strong></p>
<p>​    因为char data[0]只是个数组名, 是不占用存储空间的, 即sizeof(struct zero_buffer) = sizeof(int)。</p>
<p>​    <strong>数据包构造：</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">///  开辟</span></span><br><span class="line"><span class="keyword">if</span> ((zbuffer = (struct zero_buffer *)<span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(struct zero_buffer) + <span class="keyword">sizeof</span>(<span class="keyword">char</span>) * CURR_LENGTH)) != <span class="literal">NULL</span>)</span><br><span class="line">&#123;</span><br><span class="line">    zbuffer-&gt;len = CURR_LENGTH;</span><br><span class="line">    <span class="built_in">memcpy</span>(zbuffer-&gt;data, <span class="string">&quot;Hello World&quot;</span>, CURR_LENGTH);</span><br><span class="line"></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;%d, %s\n&quot;</span>, zbuffer-&gt;len, zbuffer-&gt;data);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>​    这个程序中，我们使用malloc申请了一片内存，大小为：sizeof(struct zero_buffer) + sizeof(char) * CURR_LENGTH)。其中sizeof(char) * CURR_LENGTH)是我们真正使用的内存空间，我们可以通过结构体成员data，直接访问这片内存。</p>
<h3 id="3-补充：为什么不用指针代替0长度数组"><a href="#3-补充：为什么不用指针代替0长度数组" class="headerlink" title="3. 补充：为什么不用指针代替0长度数组"></a>3. 补充：为什么不用指针代替0长度数组</h3><p>​    数组名在作为函数参数进行参数传递时，就<strong>相当于</strong>是一个指针。在这里，我们千万别被这句话迷惑了：数组名在作为函数参数传递时，确实传递的是一个地址，<strong>但数组名绝不是指针，两者不是同一个东西</strong>。数组名用来表征一块连续内存存储空间的地址，而指针是一个变量，编译器要给它单独再分配一个内存空间，用来存放它指向的变量的地址。</p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/C%E8%AF%AD%E8%A8%80/" rel="tag"># C语言</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/06/10/C%E8%AF%AD%E8%A8%80%E5%AE%9E%E7%8E%B0%E8%BF%9B%E5%BA%A6%E6%9D%A1%E5%92%8C%E8%BF%9E%E6%8E%A5%E7%AD%89%E5%BE%85%E6%95%88%E6%9E%9C/" rel="prev" title="C语言实现进度条和连接等待效果">
      <i class="fa fa-chevron-left"></i> C语言实现进度条和连接等待效果
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/06/15/%E7%94%B5%E5%B9%B3%E8%BD%AC%E6%8D%A2%E5%99%A8%E9%80%A0%E6%88%90GPS%E6%A8%A1%E5%9D%97%E6%97%A0%E8%BE%93%E5%87%BA/" rel="next" title="电平转换器造成GPS模块无输出">
      电平转换器造成GPS模块无输出 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E4%BB%80%E4%B9%88%E6%98%AF%E9%9B%B6%E9%95%BF%E5%BA%A6%E6%95%B0%E7%BB%84"><span class="nav-number">1.</span> <span class="nav-text">1. 什么是零长度数组</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E9%9B%B6%E9%95%BF%E5%BA%A6%E6%95%B0%E7%BB%84%E7%94%A8%E9%80%94"><span class="nav-number">2.</span> <span class="nav-text">2. 零长度数组用途</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-%E5%AE%9A%E9%95%BF%E5%8C%85"><span class="nav-number">2.1.</span> <span class="nav-text">2.1 定长包</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-%E6%8C%87%E9%92%88%E6%95%B0%E6%8D%AE%E5%8C%85"><span class="nav-number">2.2.</span> <span class="nav-text">2.2  指针数据包</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-%E5%8F%98%E9%95%BF%E6%95%B0%E6%8D%AE%E7%BC%93%E5%86%B2%E5%8C%BA"><span class="nav-number">2.3.</span> <span class="nav-text">2.3 变长数据缓冲区</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E8%A1%A5%E5%85%85%EF%BC%9A%E4%B8%BA%E4%BB%80%E4%B9%88%E4%B8%8D%E7%94%A8%E6%8C%87%E9%92%88%E4%BB%A3%E6%9B%BF0%E9%95%BF%E5%BA%A6%E6%95%B0%E7%BB%84"><span class="nav-number">3.</span> <span class="nav-text">3. 补充：为什么不用指针代替0长度数组</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">xudonglei</p>
  <div class="site-description" itemprop="description">搬砖 嵌入式</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">283</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">67</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xudonglei</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'BT0Qw9HcTpPv1a6cT1iDBXKz-gzGzoHsz',
      appKey     : 'LMCMh8v02JTMFAwKNRcgoizI',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
